﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using S4Store.Domain.NetMarketingKpi;
using LX.Web.Excel;

namespace S4Store.Domain.NetMarketingKpiReport
{
    public class NetMarketingMediaReport : NetMarketingCommonReport
    {
        public NetMarketingMediaReport()
        {
            DayDatas = new List<NetMarketingKpiDayData>();
        }

        public NetMarketingMediaReport LastMonthReport { get; set; }
        public NetMarketingStoreReport StoreReport { get; set; }

        private NetMarketingMediaGroupReport _GroupReport = null;
        public NetMarketingMediaGroupReport GroupReport
        {
            get
            {
                if (_GroupReport == null)
                {
                    _GroupReport = new NetMarketingMediaGroupReport(StoreReport, Media.Type);
                }
                return _GroupReport;
            }
        }
        public NetMarketingMedia Media { get; set; }
        public NetMarketingKpiMediaMonthConfig MediaMonthConfig { get; set; }
        public List<NetMarketingKpiDayData> DayDatas { get; set; }

        [Export("媒体名称")]
        public override string HjTitle
        {
            get { return Media.Name; }
        }

        /// <summary>
        /// 获取信息目标
        /// </summary>
        [Export("获取信息目标")]
        public override int HQXXMB
        {
            get {
                if (NetMarketingKpiMonthConfig.SYDXSJLV == 0 || NetMarketingKpiMonthConfig.XXZHLVMB == 0) return 0;

                return (NetMarketingKpiMonthConfig.DXMB * 100 * ZJTRB / NetMarketingKpiMonthConfig.SYDXSJLV / NetMarketingKpiMonthConfig.XXZHLVMB).AutoRound(); 
                //if (LastMonthReport.HQXXB == 0)
                //{
                //    return NetMarketingKpiMonthConfig.XXHQMB ;
                //}
                //return (NetMarketingKpiMonthConfig.XXHQMB * LastMonthReport.HQXXB / 100).AutoRound(); 
            }
        }
        /// <summary>
        /// 月度费用
        /// </summary>
        [Export("月度费用")]
        public override decimal YDFY
        {
            get { return MediaMonthConfig.YDFY; }
        }
        /// <summary>
        /// 计划发帖数
        /// </summary>
        [Export("计划发帖数")]
        public override int JHFTS
        {
            get { return MediaMonthConfig.JHFTS; }
        }
        /// <summary>
        /// 实际发帖数
        /// </summary>
        [Export("实际发帖数")]
        public override int FTS
        {
            get { return DayDatas.Sum(t=>t.FTS); }
        }
        /// <summary>
        /// 点击数
        /// </summary>
        [Export("点击数")]
        public override int DJS
        {
            get { return DayDatas.Sum(t => t.DJS); }
        }
        /// <summary>
        /// 单击退出数
        /// </summary>
        [Export("单击退出数")]
        public override int DJTCS
        {
            get { return DayDatas.Sum(t => t.DJTCS); }
        }
        /// <summary>
        /// 获取信息数
        /// </summary>
        [Export("获取信息数")]
        public override int HQXXS
        {
            get { return DayDatas.Sum(t => t.HQXXS); }
        }
        /// <summary>
        /// 主动来电数
        /// </summary>
        [Export("主动来电数")]
        public override int ZDLDS
        {
            get { return DayDatas.Sum(t => t.ZDLDS); }
        }
        /// <summary>
        /// 邀约来店数
        /// </summary>
        [Export("邀约来店数")]
        public override int YYLDS
        {
            get { return DayDatas.Sum(t => t.YYLDS); }
        }
        /// <summary>
        /// 资金投入比
        /// </summary>
        [Export("资金投入比", Format = "{0}%")]
        public override decimal ZJTRB
        {
            get {
                if (StoreReport.YDFY == 0) return 0;
                return YDFY * 100 / StoreReport.YDFY;
            }
        }
        /// <summary>
        /// 获取信息比
        /// </summary>
        [Export("获取信息比", Format = "{0}%")]
        public override decimal HQXXB
        {
            get
            {
                if (StoreReport.HQZYZS == 0) return 0;
                return HQZYZS * 100 / StoreReport.HQZYZS;
            }
        }
        /// <summary>
        /// 获得电话比
        /// </summary>
        [Export("获得电话比", Format = "{0}%")]
        public override decimal HDDHB
        {
            get
            {
                if (GroupReport.ZDLDS == 0) return 0;
                return (decimal)ZDLDS * 100 / (decimal)GroupReport.ZDLDS;
            }
        }
    }
}
